package cn.kgm.user.server.controller;

import cn.kgm.core.http.request.BaseController;
import cn.kgm.core.jackson.JsonUtil;
import cn.kgm.user.dto.entity.UserLoginLog;
import cn.kgm.user.server.service.UserLoginLogService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * # 技术改变自己 #
 * 用户登录日志表
 * @author kappi
 * @date   2024-04-08 13:28:48
 */
@Slf4j
@SpringBootTest
class UserLoginLogTestService extends BaseController {

    @Autowired
    private UserLoginLogService userLoginLogService;

    @Test
    void page() {
        IPage<UserLoginLog> page = getPage();
        LambdaQueryWrapper<UserLoginLog> wrapper = Wrappers.lambdaQuery(UserLoginLog.builder()
                .build());
        IPage<UserLoginLog> pages = userLoginLogService.page(page, wrapper);
        log.info("UserLoginLogTestService::page===>{}", JsonUtil.toJson(pages.getRecords()));
    }

    @Test
    void get() {
        Long id = 1L;
        UserLoginLog userLoginLog =userLoginLogService.getById(id);
        log.info("UserLoginLogTestService::get===>{}", JsonUtil.toJson(userLoginLog));
    }

    @Test
    void save() {
        UserLoginLog userLoginLog = UserLoginLog.builder()
                .build();
            userLoginLogService.save(userLoginLog);
        log.info("UserLoginLogTestService::save===>{}", JsonUtil.toJson(userLoginLog));
    }

    @Test
    void update() {
        UserLoginLog userLoginLog = UserLoginLog.builder()
                .build();
            userLoginLogService.updateById(userLoginLog);
        log.info("UserLoginLogTestService::update===>{}", JsonUtil.toJson(userLoginLog));
    }

    @Test
    void delete() {
        Long[] ids = new Long[]{0L};
            userLoginLogService.update(Wrappers.<UserLoginLog>lambdaUpdate()
                .set(UserLoginLog::getIsDel, true)
                .in(UserLoginLog::getId, ids));
        log.info("UserLoginLogTestService::delete===>{}", JsonUtil.toJson(ids));
    }
}
